<?php

/**
 * Base response class for framework
 * 
 * PHP version 5
 * 
 * @category  Framework
 * @package   Abacus11_Framework
 * @author    Philippe Jausions <jausions@php.net>
 * @copyright 2008 11abacus / Philippe Jausions
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD
 * @link      http://pear.11abacus.com/package/Abacus11_Framework
 */

/**
 * Class dependencies
 */
require_once 'Abacus11/Framework/DataHolder.php';


/**
 * Base response class for framework
 * 
 * @category  Framework
 * @package   Abacus11_Framework
 * @author    Philippe Jausions <jausions@php.net>
 * @copyright 2008 11abacus / Philippe Jausions
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD
 * @link      http://pear.11abacus.com/package/Abacus11_Framework
 * 
 * @property      Abacus11_Framework_DataHolder      $data
 * @property      string                             $returnTo
 * @property      Abacus11_Framework::STATUS_*       $code
 * @property-read Abacus11_Framework_ModuleInterface $module
 * @property-read string                             $action
 * @property-read Abacus11_Framework_Request         $request
 */
class Abacus11_Framework_Response  
{
    /**
     * Data holder
     * 
     * @var Abacus11_Framework_DataHolder
     */
    protected $data;

    /**
     * Module instance
     * 
     * @var Abacus11_Framework_ModuleInterface
     */
    protected $module;

    /**
     * Action name this is the response to
     *
     * @var string
     */
    protected $action;

    /**
     * Response code
     *
     * @var Abacus11_Framework::STATUS_* constant
     */
    protected $code = self::RESULT_ERROR;

    /**
     * Where to return to
     *
     * @var mixed
     */
    protected $returnTo = null;

    /**
     * Original request
     *
     * @var Abacus11_Framework_Request
     */
    protected $request;
    
    /**
     * Enter description here...
     *
     * @param Abacus11_Framework_ModuleInterface $module  Module instance
     * @param string                             $action
     * @param Abacus11_Framework_Request         $request Original request
     */
    public function __construct(Abacus11_Framework_ModuleInterface $module, 
        $action, Abacus11_Framework_Request $request)
    {
        $this->data    = new Abacus11_Framework_DataHolder(array());
        $this->module  = $module;
        $this->action  = $action;
        $this->request = $request;
    }

    /**
     * Property getter
     *
     * @param string $name Property name
     * 
     * @return mixed Property value
     */
    public function __get($name)
    {
        switch ($name) {
        case 'data':
            return $this->data;
        case 'module':
        case 'action':
        case 'code':
        case 'request':
        case 'returnTo':
            return $this->$name;
        }
        throw new Abacus11_Framework_Exception_NotFound('"'.$name
                                         .'" is not a member of '.__CLASS__, 
                                         Abacus11_Framework::SCOPE_RESPONSE);
    }

    /**
     * Property setter
     *
     * @param string $name  Property name
     * @param mixed  $value New value
     * 
     * @return void
     */
    public function __set($name, $value)
    {
        switch ($name) {
        case 'data':
            return $this->data->exchangeArray($value);
        case 'code':
        case 'returnTo':
            $this->$name = $value;
            return;
        case 'module':
        case 'action':
        case 'request':
            throw new Abacus11_Framework_Exception('Class member "'
                                                   .$name.'" is read-only');
        }
        throw new Abacus11_Framework_Exception_NotFound('"'.$name
                                         .'" is not a member of '.__CLASS__, 
                                         Abacus11_Framework::SCOPE_RESPONSE);
    }
}

?>